from django.http import HttpResponse, JsonResponse
from django.views.decorators.http import require_http_methods
import base64, json
from .confs.conf import get_mirror_conn
from django.views.decorators.csrf import csrf_exempt

def_response_o = {
    "code": 0,
    "result": "",
    "message": "",
    "type": 'success',
  }

select="""
select * from dlz_task_info where code= 'order_code' and deal_flag=2
"""

select_all="""
select * from dlz_task_info where deal_flag=1
"""

@require_http_methods(["GET"])
def get_is_feedback_by_code(request):
    global select
    params = request.GET
    re = json.loads(json.dumps(def_response_o,ensure_ascii=False))
    code = params['code'] if 'code' in params.keys() else ''

    if not code:
        re['code'] = 404
        re['type'] = 'fail'
        re['message'] = "请传递code"
        return JsonResponse(re)

    db_conn = get_mirror_conn()
    sql=select.replace('order_code' , code)
    result = db_conn.query_one(sql)
    re['result'] = result
    return JsonResponse(re)


@require_http_methods(["GET"])
def get_all_mail(request):
    global select_all
    re = json.loads(json.dumps(def_response_o,ensure_ascii=False))
    db_conn = get_mirror_conn()
    sql=select_all
    result = db_conn.query_all(sql)
    print(result)
    re['result'] = result
    return JsonResponse(re)

